//
//  SendViewController.m
//  customer
//
//  Created by 往返网络 on 17/4/17.
//  Copyright © 2017年 com. All rights reserved.
//

#import "SendViewController.h"
#import "FahuoTableViewCell.h"
#import "FahuoDetailViewController.h" //发货运单详情界面，没有操作
#import "ScannerViewController.h"  //扫描页面
#import "PublicMethod.h"
#import "SendListModel.h"

#define begin_x 30.0/W_BASE*SCREEN_W  //搜索页的起始
//定义发货运单列表URL
#define URL_SENDLIST [NSString stringWithFormat:@"%@/Appcustomernew/Order/orderList?type=get",BASE_URL]
@interface SendViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
@property (nonatomic,strong)UITableView * tableview;
@property (nonatomic,strong)NSMutableArray * datasource;
@property (nonatomic,strong)UIView * searchview; //搜索view
@property (nonatomic,strong)UIView * backview; //透明背景
@property (nonatomic,strong)AFHTTPSessionManager* manger;
@end

@implementation SendViewController

{
    UIButton * statusbtn; //状态btn
    //状态选择
    UIView * statusview;  //状态view
    UIButton * iconbtn; //
    //物流公司名称
    UIView * comanyview;  //公司view
    UITextField * searchtf; //搜索内容
    UIButton * compltebtn; //完成
    UIButton * resetbtn; //重置
    NSInteger current_tag; //当前状态选择按钮的tag值
    BOOL isClick_stuatusbtn; //当前状态btn有没有被选中
    //搜索的参数
    NSString * token;
    NSString * orderState; //状态
    NSString * searchContent; //内容
    NSInteger  page;
    NSInteger  totalPage; //总页数
}
- (void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self createUI];
    
    // 初始化搜索参数
    
    orderState = @"";
    
    searchContent = @"";
    
    page = 0;
    //初始化状态btn有没有被选中（搜索页面中）
    
    isClick_stuatusbtn = NO;
    
    current_tag = 5001;

    //注册通知
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(receivenotice) name:@"LOGIN" object:nil];
    
    

    
    // Do any additional setup after loading the view.
}

- (void)receivenotice{

    // 初始化搜索参数
    
    orderState = @"";
    
    searchContent = @"";
    
    page = 0;
    
    [self loadData];
    

}


- (void)loadData{
    
    
  
    NSUserDefaults * userdefalut = [NSUserDefaults standardUserDefaults];
    
    token = [userdefalut objectForKey:USER_TOCKE];
    
    page = 0;
    
    NSString * url = [NSString stringWithFormat:@"%@&token=%@&orderState=%@&searchContent=%@&page=%ld&pageSize=10&type=1",URL_SENDLIST,token,orderState,searchContent,page];
    
    //有中文搜索，需要转码
    NSString * URL  = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSLog(@"发货列表 url %@",url);
    
    [self.manger GET:URL parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject) {
            
            NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            
            NSInteger code = [dict[@"code"]integerValue];
            
            totalPage = [dict[@"totalPage"]integerValue];
            
            if (code == 0) {
                
                //清除原有数据
                
                [self.datasource removeAllObjects];
                
                NSArray * datarr = dict[@"data"];
                
                
                for (NSDictionary * data in datarr) {
                    
                    
                    SendListModel * model = [[SendListModel alloc]init];
                    
                    model.id = [NSString stringWithFormat:@"%@",data[@"id"]];
                    model.order_id = [NSString stringWithFormat:@"%@",data[@"order_id"]];
                    model.to_person = [NSString stringWithFormat:@"%@",data[@"to_person"]];
                    model.to_mobile = [NSString stringWithFormat:@"%@",data[@"to_mobile"]];
                    model.company_name = [NSString stringWithFormat:@"%@",data[@"company_name"]];
                    model.created_time = [NSString stringWithFormat:@"%@",data[@"created_time"]];
                    model.order_state = [NSString stringWithFormat:@"%@",data[@"order_state"]];
                    model.fee = [NSString stringWithFormat:@"%@",data[@"fee"]];
                    //货物名称。 数量 。
                    
                        if (![data[@"goods_name1"] isEqualToString:@""]) {
                            model.goods_name = data[@"goods_name1"];
                            model.goods_num = data[@"goods_num1"];
                            model.goods_volume = data[@"goods_volume1"];
                            model.goods_weight = data[@"goods_weight1"];
                            

                            
                        }else if (![data[@"goods_name2"] isEqualToString:@""]) {
                            model.goods_name = data[@"goods_name2"];
                            model.goods_num = data[@"goods_num2"];
                            model.goods_volume = data[@"goods_volume2"];
                            model.goods_weight = data[@"goods_weight2"];
                            

                        }else if (![data[@"goods_name3"] isEqualToString:@""]) {
                            model.goods_name = data[@"goods_name3"];
                            model.goods_num = data[@"goods_num3"];
                            model.goods_volume = data[@"goods_volume3"];
                            model.goods_weight = data[@"goods_weight3"];
                            

                        }else{
                            
                            model.goods_name = @"";
                            model.goods_num = @"";
                            model.goods_volume = @"";
                            model.goods_weight = @"";
                        

                        }

                    [self.datasource addObject:model];
                 

                }
                
                
                //刷新tableview
                
                [_tableview reloadData];
                
                [self.tableview.header endRefreshing];

                

                
            }else{
                
                [self.tableview.header endRefreshing];

                
                ALERT(@"提示", dict[@"info"], self, @"确定", nil);
                
            }
            
            
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        [self.tableview.header endRefreshing];

        ALERT(@"提示", @"网络请求失败", self, @"确定", nil);
        
    }];
    
    
}

- (void)loadMoredata{
    
    
    
    NSUserDefaults * userdefalut = [NSUserDefaults standardUserDefaults];
    
    token = [userdefalut objectForKey:USER_TOCKE];
    
    
    NSString * url = [NSString stringWithFormat:@"%@&token=%@&orderState=%@&searchContent=%@&page=%ld&pageSize=10&type=1&totalPage=%ld",URL_SENDLIST,token,orderState,searchContent,page+1,totalPage];
    
    //有中文搜索，需要转码
    NSString * URL  = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSLog(@"more url %@",url);
    
    [self.manger GET:URL parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject) {
            
            NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            
            NSInteger code = [dict[@"code"]integerValue];
            
            if (code == 0) {
                
                NSArray * datarr = dict[@"data"];
                
                
                for (NSDictionary * data in datarr) {
                    
                    
                    SendListModel * model = [[SendListModel alloc]init];
                    
                    model.id = [NSString stringWithFormat:@"%@",data[@"id"]];
                    model.order_id = [NSString stringWithFormat:@"%@",data[@"order_id"]];
                    model.to_person = [NSString stringWithFormat:@"%@",data[@"to_person"]];
                    model.to_mobile = [NSString stringWithFormat:@"%@",data[@"to_mobile"]];
                    model.company_name = [NSString stringWithFormat:@"%@",data[@"company_name"]];
                    model.created_time = [NSString stringWithFormat:@"%@",data[@"created_time"]];
                    model.order_state = [NSString stringWithFormat:@"%@",data[@"order_state"]];
                    model.fee = [NSString stringWithFormat:@"%@",data[@"fee"]];
                    
                    //货物名称。 数量 。
                    if (![data[@"goods_name1"] isEqualToString:@""]) {
                        model.goods_name = data[@"goods_name1"];
                        model.goods_num = data[@"goods_num1"];
                        model.goods_volume = data[@"goods_volume1"];
                        model.goods_weight = data[@"goods_weight1"];
                        
                        
                        
                    }else if (![data[@"goods_name2"] isEqualToString:@""]) {
                        model.goods_name = data[@"goods_name2"];
                        model.goods_num = data[@"goods_num2"];
                        model.goods_volume = data[@"goods_volume2"];
                        model.goods_weight = data[@"goods_weight2"];
                        
                        
                    }else if (![data[@"goods_name3"] isEqualToString:@""]) {
                        model.goods_name = data[@"goods_name3"];
                        model.goods_num = data[@"goods_num3"];
                        model.goods_volume = data[@"goods_volume3"];
                        model.goods_weight = data[@"goods_weight3"];
                        
                        
                    }else{
                        
                        model.goods_name = @"";
                        model.goods_num = @"";
                        model.goods_volume = @"";
                        model.goods_weight = @"";
                        
                        
                    }
                    
                    [self.datasource addObject:model];
                    
                    
                }
                
                page++;
                
                //刷新tableview
                
                [_tableview reloadData];
                
                [self.tableview.footer endRefreshing];

                
            }else {
                
                
                if (page == totalPage-1) {
                    
                    [self.tableview.footer endRefreshing];
                    
                }
                else{
                
                    [self.tableview.footer endRefreshing];
                    
                    ALERT(@"提示", dict[@"info"], self, @"确定", nil);
                    

                
                }
            }
            
            
            
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        
        [self.tableview.footer endRefreshing];

        ALERT(@"提示", @"网络请求失败", self, @"确定", nil);
        
    }];
    
    
}
- (void)setNavigationBar{


    float fontsize = 17;
    
    fontsize = SCREEN_H < 667 ? 15 : 19;
    
    if (SCREEN_H == 667) {
        
        fontsize = 17;
    }
    
    self.navigationItem.title = @"发货运单";
    
    
    //设置导航条
    self.navigationController.navigationBar.barTintColor = COLORRGBA(7, 24, 57, 1);
    self.navigationController.navigationBar.translucent = NO; //关闭导航条的半透明化
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName :[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:fontsize]};
    
    //设置搜索按钮
    UIButton * searchbtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100.0/W_BASE*SCREEN_W, 88.0/H_BASE*SCREEN_H)];
    
    searchbtn.titleLabel.font = [UIFont fontWithName:@"iconfont" size:fontsize];
    
    [searchbtn setTitle:@"\U0000e6ac" forState:UIControlStateNormal];
    
    [searchbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    UIBarButtonItem * item = [[UIBarButtonItem alloc]initWithCustomView:searchbtn];
    
    self.navigationItem.rightBarButtonItem = item;
    
    [searchbtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 60.0/W_BASE*SCREEN_W, 0, 0)];
    
    [searchbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //设置扫一扫功能
    
    UIButton * scannerbtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100.0/W_BASE*SCREEN_W, 88.0/H_BASE*SCREEN_H)];
    
    scannerbtn.titleLabel.font = [UIFont fontWithName:@"iconfont" size:fontsize];
    
    [scannerbtn setTitle:@"\U0000e6ec" forState:UIControlStateNormal];
    
    [scannerbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    UIBarButtonItem * item1 = [[UIBarButtonItem alloc]initWithCustomView:scannerbtn];
    
    self.navigationItem.leftBarButtonItem = item1;
    
    [scannerbtn setTitleEdgeInsets:UIEdgeInsetsMake(0,0 , 0, 60.0/W_BASE*SCREEN_W)];
    
    [scannerbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];


    searchbtn.tag = 1000;

    scannerbtn.tag = 2000;
    
    //设置电池颜色等白色
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
    

}

#pragma mark - - - -  - - - - - - - -- -  - - - 创建搜索试图 - - -  - - - - -- - -  -

- (void)createSearchView{
    
    
    float fontsize = 13;
    
    fontsize = SCREEN_H < 667 ? 11 : 15;
    
    if (SCREEN_H == 667) {
        
        fontsize = 13;
    }
    
    _backview = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_W, 0, 90.0/W_BASE*SCREEN_W, SCREEN_H)];
    
    _backview.backgroundColor = COLORRGBA(150, 150, 150, 0.25);
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick:)];
    
    [_backview addGestureRecognizer:tap];
    
    [WINDOW addSubview:_backview];
    
    _searchview = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_W+90.0/W_BASE*SCREEN_W, 0, SCREEN_W - 90.0/W_BASE*SCREEN_W, SCREEN_H)];
    
    _searchview.backgroundColor = [UIColor whiteColor];
    
    UITapGestureRecognizer * tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick2:)];
    
    [_searchview addGestureRecognizer:tap1];
    
    
    //贴在window上将视图置于最前面,盖住navigationbar /tabbar
    
    [WINDOW addSubview:_searchview];
    
    //状态选择
    
    UILabel * status = [[UILabel alloc]initWithFrame:CGRectMake(begin_x, 40.0/H_BASE*SCREEN_H, 130.0/W_BASE*SCREEN_W, 70.0/H_BASE*SCREEN_H)];
    
    status.textAlignment = NSTextAlignmentLeft;
    
    status.text = @"状态选择";
    
    status.textColor = COLORRGBA(102, 102, 102, 1);
    
    status.font = [UIFont systemFontOfSize:fontsize];
    
    [_searchview addSubview:status];
    
    statusbtn = [[UIButton alloc]initWithFrame:CGRectMake(begin_x, 40.0/H_BASE*SCREEN_H, SCREEN_W-90.0/W_BASE*SCREEN_W, 70.0/H_BASE*SCREEN_H)];

    [_searchview addSubview:statusbtn];
    
    [statusbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    
    statusbtn.tag = 6000;
    
    iconbtn = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetWidth(_searchview.frame)- 90.0/W_BASE*SCREEN_W, CGRectGetMinY(statusbtn.frame), 60.0/W_BASE*SCREEN_W, CGRectGetHeight(statusbtn.frame))];
    
    [iconbtn setTitle:@"\U0000e6a6" forState:UIControlStateNormal];
    
    [_searchview addSubview:iconbtn];
    
    [iconbtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    iconbtn.titleLabel.font = [UIFont fontWithName:@"iconfont" size:fontsize+5];
    
    iconbtn.tag = 6000;
    
    [iconbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    statusview = [[UIView alloc]initWithFrame:CGRectMake(begin_x, CGRectGetMaxY(statusbtn.frame),CGRectGetWidth(_searchview.frame)- 60.0/W_BASE*SCREEN_W , 206.0/H_BASE*SCREEN_H)];
    
    [_searchview addSubview:statusview];
    
    NSArray * statusarr = @[@"全部",@"未配载",@"已配载",@"已发车",@"已到达",@"已完成"];
    
    NSInteger m = 0;
    
    for (NSInteger i = 0; i < 3; i++) {
        
        for (NSInteger j = 0; j <2; j++) {
            
            UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(i*(186.0+21.0)/W_BASE*SCREEN_W,j*(83.0+20.0)/H_BASE*SCREEN_H , 186.0/W_BASE*SCREEN_W, 83.0/H_BASE*SCREEN_H)];
            
            btn.backgroundColor = COLORRGBA(240, 240, 240, 1);
            
           [btn setTitle:statusarr[m] forState:UIControlStateNormal];
            
            [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

            [statusview addSubview:btn];
            
            btn.titleLabel.font = [UIFont systemFontOfSize:fontsize - 1];
            
            btn.layer.cornerRadius = 2;
            
            btn.clipsToBounds = YES;
            
            btn.tag = 5000+1+m;
            
            if (btn.tag == 5001) {
                
                //默认一进来全部为蓝色
                
                [btn setBackgroundColor:COLORRGBA(229, 242, 255, 1)];
                
                //添加图片
                UIImageView * im = [[UIImageView alloc]initWithFrame:CGRectMake(btn.frame.size.width - 35.0/W_BASE*SCREEN_W, btn.frame.size.height - 35.0/W_BASE*SCREEN_W, 35.0/W_BASE*SCREEN_W, 35.0/W_BASE*SCREEN_W)];
                
                im.image = [UIImage imageNamed:@"statusx"];
                
                [btn addSubview:im];
                
            }
            
            [btn addTarget:self action:@selector(statusBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            
            m++;

        }
        
    }
    
    
    statusview.hidden = YES;

    
     //公司名称
    
    comanyview = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(statusbtn.frame), SCREEN_W - 90.0/W_BASE*SCREEN_W, 173.0/H_BASE*SCREEN_H)];
    
    comanyview.backgroundColor = [UIColor whiteColor];
    
    [_searchview addSubview:comanyview];
    
    UIView * breakline = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W - 90.0/W_BASE*SCREEN_W, 1)];
    
    
    breakline.backgroundColor = COLORRGBA(239, 239, 239, 1);
    
    [comanyview addSubview:breakline];
    
    
    
    UILabel * comanylab = [[UILabel alloc]initWithFrame:CGRectMake(begin_x, 0, 200.0/W_BASE*SCREEN_W, 75.0/H_BASE*SCREEN_H)];
    
    comanylab.text = @"物流公司名称";
    
    comanylab.font = [UIFont systemFontOfSize:fontsize];
    
    comanylab.textColor = COLORRGBA(102, 102, 102, 1);
    
    [comanyview addSubview:comanylab];
    
    
    searchtf = [[UITextField alloc]initWithFrame:CGRectMake(begin_x, CGRectGetMaxY(comanylab.frame), SCREEN_W - 150.0/W_BASE*SCREEN_W, 78.0/H_BASE*SCREEN_H)];
    
    searchtf.backgroundColor = [UIColor whiteColor];
    
    searchtf.borderStyle = UITextBorderStyleRoundedRect;
    
    searchtf.placeholder = @"输入搜索内容";
    
    searchtf.font = [UIFont systemFontOfSize:fontsize];
    
    [comanyview addSubview:searchtf];
    
    searchtf.textAlignment = NSTextAlignmentCenter;
    
    searchtf.layer.borderColor = [COLORRGBA(240, 240, 240, 1)CGColor];
    
    searchtf.clipsToBounds = YES;
    
    searchtf.layer.borderWidth = 10.0/H_BASE*SCREEN_H;
    
    searchtf.layer.cornerRadius = 6;
    
    searchtf.delegate = self;
    
    
    
    //完成。。重置按钮 ....
    
    compltebtn = [[UIButton alloc]initWithFrame:CGRectMake(0,SCREEN_H - 80.0/H_BASE*SCREEN_H, SCREEN_W*0.5-45.0/W_BASE*SCREEN_W, 80.0/H_BASE*SCREEN_H)];
    
    compltebtn.backgroundColor = [UIColor whiteColor];
    
    compltebtn.layer.borderColor = [COLORRGBA(204, 204, 204, 1)CGColor];
    
    compltebtn.layer.borderWidth = 1;
    
    [compltebtn setTitle:@"完成" forState:UIControlStateNormal];
    
    [_searchview addSubview:compltebtn];
    
    compltebtn.titleLabel.font = [UIFont systemFontOfSize:fontsize + 2];
    
    [compltebtn setTitleColor:COLORRGBA(204, 204, 204, 1) forState:UIControlStateNormal];
    
    resetbtn = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(compltebtn.frame), CGRectGetMinY(compltebtn.frame), CGRectGetWidth(compltebtn.frame), CGRectGetHeight(compltebtn.frame))];
    
    [resetbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    resetbtn.titleLabel.font = [UIFont systemFontOfSize:fontsize + 2];
    
    [resetbtn setBackgroundColor:COLORRGBA(59,214 , 117, 1)];
    
    [_searchview addSubview:resetbtn];
    
    [resetbtn setTitle:@"重置" forState:UIControlStateNormal];
    
    resetbtn.userInteractionEnabled = NO;
    
    compltebtn.tag = 3000;
    
    resetbtn.tag = 4000;
    
    [compltebtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [resetbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    


}

- (void)createUI{
    
    
    //设置导航条
    [self setNavigationBar];
    
    [self createSearchView];

    _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H) style:UITableViewStylePlain];
    
    _tableview.backgroundColor = COLORRGBA(239, 239, 239, 1);
    
    _tableview.delegate = self;
    
    _tableview.dataSource = self;
    
    [self.view addSubview:_tableview];
    
    //注册cell
    
    [_tableview registerClass:[FahuoTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    _tableview.showsVerticalScrollIndicator = NO;
    
    _tableview.showsHorizontalScrollIndicator = NO;
    
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    //设置MJRefresh
    
    
    MJRefreshNormalHeader* header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [self loadData];
        
        
    }];
    
    
    [header setTitle:@"努力加载中 ..." forState:MJRefreshStatePulling];
    [header setTitle:@"正在刷新" forState:MJRefreshStateRefreshing];
    
    self.tableview.header = header;
    
    
    MJRefreshBackNormalFooter * footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        
        [self loadMoredata];
        
    }];
    
    [footer setTitle:@"加载更多" forState:MJRefreshStatePulling];
    
    [footer setTitle:@"正在加载" forState:MJRefreshStateRefreshing];
    
    self.tableview.footer = footer;
    

}

#pragma mark - ------ - - - - -  Tableview Delegate - --  - - 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{


    return 365.0/H_BASE*SCREEN_H;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    FahuoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.isfahuo = @"YES";

    SendListModel * model = [self.datasource objectAtIndex:indexPath.row];
    
    [cell refreshCellWithModel:model];
    
    cell.block1 = ^(NSString * isPhone){
    
                   //拨打电话
            
            NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",isPhone];
            
            UIWebView * callWebview = [[UIWebView alloc] init];
            
            [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
            
            [self.view addSubview:callWebview];
            
        
       
    };
    
    cell.block2 = ^(NSString * followid){
        
        //运单详情界面
        
        FahuoDetailViewController * detail = [[FahuoDetailViewController alloc]init];
        
        detail.isDetail = @"NO";
        
        NSString * oid = model.id;
        
        detail.oid = oid;
        
        [self presentViewController:detail animated:YES completion:nil];
        
    
    };
    
    
    return cell;
    
    
}

- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath{

   //进入详情界面
    
    SendListModel * model = [self.datasource objectAtIndex:indexPath.row];

    
    FahuoDetailViewController * detail = [[FahuoDetailViewController alloc]init];
    
    detail.isDetail = @"YES";
    
    detail.oid = model.id;
    
    
    [self presentViewController:detail animated:YES completion:nil];
    

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{


    return self.datasource.count;


}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{


    [self.view endEditing:YES];
    
    [searchtf resignFirstResponder];
    
    
    return YES;

}

#pragma mark - - -- -- Action - - - - -

- (void)enterClick:(UIButton* )btn{


    
    switch (btn.tag) {
            
            //搜索页面
        case 1000:
        {
        
            [self searchUp];
            
            break;

        }
            
            
            case 2000:
        {
            
            ScannerViewController * scannervc = [[ScannerViewController alloc]init];
            
            [self.navigationController pushViewController:scannervc animated:YES];


            break;
            
        }
            
            case 3000:
        {
            
            NSLog(@"完成");

            //传送搜索数据...tableview重新请求数据。。刷新tableview
            
            //一些相关搜索参数更改
            
            
            orderState = [NSString stringWithFormat:@"%ld",current_tag-5001];
            
            if ([orderState isEqualToString:@"0"]||[orderState isEqualToString:@"-5001"]) {
                
                orderState = @"";
                
            }
            searchContent = searchtf.text;
            
            [self loadData];
            
            [self searchDown];
            
            break;
            
        }
            
            case 4000:
        {
            NSLog(@"重置");
            
            //如果statusbtn没有被点击，则不可重置
            
            
            //状态view变到展开的位置
            
            for (UIButton * btn in statusview.subviews) {
                
                if (btn.tag >= 5001) {
                    
                    btn.hidden = NO;
                    
                    if (btn.tag == 5001) {
                        
                        [btn setTitle:@"全部" forState:UIControlStateNormal];
                        
                    }
                    
                }
                
                
                
            }
            //更改statusview的位置

            CGRect rect = CGRectMake(begin_x, CGRectGetMaxY(statusbtn.frame),CGRectGetWidth(_searchview.frame)- 60.0/W_BASE*SCREEN_W , 206.0/H_BASE*SCREEN_H);
            
            statusview.frame = rect;
            
            //更改物流公司的位置
            
            CGRect rect1 = CGRectMake(0, CGRectGetMaxY(statusview.frame), SCREEN_W - 90.0/W_BASE*SCREEN_W, 173.0/H_BASE*SCREEN_H);
            
            comanyview.frame = rect1;
            
            //重置之后更改 状态选择按钮的状态，为未被选中
            isClick_stuatusbtn = NO;
            
            //更改当前选定的按钮
            
            current_tag = 5001; //默认为全部
            
            orderState = @"";
            
            searchContent = @"";

            [self loadData];
            

            break;
            
        }
            
            case 6000:
        {
            
            //状态选择BTN的点击
            //icon样式更改
            NSLog(@"状态选择BTN的点击");

            static BOOL isClick = NO;
            
            if (!isClick) {
                
                //状态选择view弹出
                [self statusViewUp];
                
                resetbtn.userInteractionEnabled = YES;
                
            }
            else{
            
                //状态选择view收起
                [self statusViewDown];
                
                resetbtn.userInteractionEnabled = NO;
                
            }
            
            isClick = !isClick;

            
            break;
            
            
        }
            
            
        default:
            break;
    }
    
    
}

#pragma mark   - -- - - - -状态选择按钮的点击事件  － －－ － － － － 

- (void)statusBtnClick:(UIButton *)btn{

    //设置当前选中的btn（状态按钮）的tag值
    
    current_tag = btn.tag;
    
    
    NSLog(@"current tag %ld",current_tag);
    
    NSArray * statusarr = @[@"全部",@"未配载",@"已配载",@"已发车",@"已到达",@"已完成"];

    //点击按钮是，当前按钮变亮，变色
    
    
    if (!isClick_stuatusbtn) {
        
        NSLog(@"click");
        
        //移除btn
        
        for (UIButton * btn in statusview.subviews) {
            
            
            if (btn.tag == 5001) {
                
                //更改第一个按钮的文字
                
                [btn setTitle:statusarr[current_tag-1-5000] forState:UIControlStateNormal];
                

            }else{
            
            
                btn.hidden = YES;
                
            }
            
        }
        
        
        //更改statusview的大小
        
        CGRect rect = CGRectMake(begin_x, CGRectGetMaxY(statusbtn.frame),CGRectGetWidth(_searchview.frame)- 60.0/W_BASE*SCREEN_W , 103.0/H_BASE*SCREEN_H);
        
        statusview.frame = rect;
        
        //更改comanyview的大小
        
        CGRect rect1 = CGRectMake(0, CGRectGetMaxY(statusview.frame), SCREEN_W - 90.0/W_BASE*SCREEN_W, 173.0/H_BASE*SCREEN_H);
        
        comanyview.frame = rect1;
        
        
    }
    else{
    
        NSLog(@"cancel");
        
        //更改当前选定的按钮为0 。。。
        
        current_tag = 0;
        
        //状态view变到展开的位置
        for (UIButton * btn in statusview.subviews) {
            
            if (btn.tag >= 5001) {
                
                btn.hidden = NO;
                
                if (btn.tag == 5001) {
                    
                    [btn setTitle:@"全部" forState:UIControlStateNormal];
                    
                }
                
            }
            
            
            
        }
        
        CGRect rect = CGRectMake(begin_x, CGRectGetMaxY(statusbtn.frame),CGRectGetWidth(_searchview.frame)- 60.0/W_BASE*SCREEN_W , 206.0/H_BASE*SCREEN_H);
        
        statusview.frame = rect;
        
        //更改物流公司的位置
        
        CGRect rect1 = CGRectMake(0, CGRectGetMaxY(statusview.frame), SCREEN_W - 90.0/W_BASE*SCREEN_W, 173.0/H_BASE*SCREEN_H);
        
        comanyview.frame = rect1;


        }
    
    isClick_stuatusbtn = !isClick_stuatusbtn;
    
    


}

- (void)tapClick:(UITapGestureRecognizer *)tap{

    
    [searchtf resignFirstResponder];
    
    [self searchDown];
    
}

- (void)tapClick2:(UITapGestureRecognizer *)tap{
    
    
    [searchtf resignFirstResponder];
    
}

#pragma mark  - -- -  -- 状态选择按钮的点击事件 －－ － －－ － －


#pragma mark -   - -- - - - 搜索页面弹出 动画- - - -- - -

- (void)searchUp{


    //搜索页面弹出
    [UIView animateWithDuration:0.5 animations:^{
        
        
        CGRect rect2 = CGRectMake(90.0/W_BASE*SCREEN_W, 0, SCREEN_W - 90.0/W_BASE*SCREEN_W, SCREEN_H);
        
        _searchview.frame = rect2;
        
        
    } completion:^(BOOL finished) {
        
        
        CGRect rect1 = CGRectMake(0, 0, 90.0/W_BASE*SCREEN_W, SCREEN_H);
        
        _backview.frame = rect1;
        
        
    }];


}

#pragma mark  - - -- - - - -- 搜索页面消失动画 - -- - - -

- (void)searchDown{


    CGRect rect1 = CGRectMake(SCREEN_W, 0, 90.0/W_BASE*SCREEN_W, SCREEN_H);
    
    _backview.frame = rect1;
    
    [UIView animateWithDuration:0.5 animations:^{
        
        
        CGRect rect2 = CGRectMake(SCREEN_W+90.0/W_BASE*SCREEN_W, 0, SCREEN_W - 90.0/W_BASE*SCREEN_W, SCREEN_H);
        
        _searchview.frame = rect2;
        
        
    } completion:^(BOOL finished) {
        
        
        
    }];
    



}

#pragma mark - - --  -- -  状态选择view的弹出 － －－ －  － － － －
- (void)statusViewUp{

    [UIView animateWithDuration:0.5 animations:^{
        
        //更改icon
        [iconbtn setTitle:@"\U0000e6a5" forState:UIControlStateNormal];
        
        //显示状态按钮
        
        statusview.hidden = NO;
        
        //更改物流公司的位置
        
        CGRect rect = CGRectMake(0, CGRectGetMaxY(statusview.frame), SCREEN_W - 90.0/W_BASE*SCREEN_W, 173.0/H_BASE*SCREEN_H);
        
        comanyview.frame = rect;
        
        
    } completion:nil];




}

- (void)statusViewDown{


    [UIView animateWithDuration:0.5 animations:^{
        
        //
        [iconbtn setTitle:@"\U0000e6a6" forState:UIControlStateNormal];
        
        //移除状态按钮
        
        statusview.hidden = YES;
        
        //更改物流公司位置
        
        CGRect rect = CGRectMake(0, CGRectGetMaxY(statusbtn.frame), SCREEN_W - 90.0/W_BASE*SCREEN_W, 173.0/H_BASE*SCREEN_H);
        
        comanyview.frame = rect;
        
        
    } completion:nil];
    





}
#pragma mark  - - -- - - - - 状态选择view的收起 - -- - - -- - - -

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self.view endEditing:YES];
    
    [searchtf resignFirstResponder];


}
#pragma mark  - - -- -  懒加载 - - - - - -

- (NSMutableArray *)datasource{

    if (!_datasource) {
        
        _datasource  = [NSMutableArray array];
        
    }

    return _datasource;
    

}

- (AFHTTPSessionManager*)manger{
    
    _manger = [AFHTTPSessionManager manager];
    
    _manger.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    _manger.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json", nil];
    
    return _manger;
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
